#c preprocessor
Explore tagged Tumblr posts
Text
C Preprocessor: Forcing More Scans
The basic idea of how the C preprocessor works is that it scans the token list for macros to expand, and after every expansion, it re-scans the result to see if anything else needs to be expanded.
Many of the more advanced C preprocessor tricks rely on this either implicitly, or explicitly force extra scans. Here's a simple brute force example of the latter:
#define SCAN1(...) __VA_ARGS__ #define SCAN4(...) SCAN1(SCAN1(SCAN1(SCAN1(__VA_ARGS__)))) #define SCAN16(...) SCAN4(SCAN4(SCAN4(SCAN4(__VA_ARGS__)))) #define SCAN64(...) SCAN16(SCAN16(SCAN16(SCAN16(__VA_ARGS__)))) #define SCAN256(...) SCAN64(SCAN64(SCAN64(SCAN64(__VA_ARGS__))))
If the preprocessor just sees "FOO", it will look for a macro named "FOO" and if so, it will replace it and then resume scanning from the beginning of the replacement - "re-scanning" the result of expanding FOO.
If it sees "SCAN1(FOO)", it will first try to expand FOO. Let's say FOO is a macro, so it's expanded and rescanned. So far the same. Then it will try to expand "SCAN1" with the result of expanding (and re-scanning) FOO. And then it will rescan everything starting from the result of replacing SCAN1, which includes the already replaced and re-scanned result of FOO. So it adds one more scan over the result of FOO.
Now what happens if the preprocessor sees SCAN1(SCAN1(FOO))? Well, it will try to expand the argument list of the outer SCAN1, which requires expanding the argument list of the inner SCAN1, so it expands FOO, and again if FOO was a macro then the result is rescanned, then it expands the inner SCAN1, then it resumes scanning from the start of the result of the inner SCAN1, then finally it expands the outer SCAN1, and again it resumes scanning from where the result of the outer SCAN1 starts.
So "SCAN256(X())" will force the preprocessor to scan and try expanding the result of "X()" 256 extra times.
To be clear, that's not enough by itself to recursively expand macros - if X() expands to "... X() ...", there is a separate protection involved that prevents the "X" token from expanding again, because it was the result of expanding a macro with the same name. (Online this is sometimes referred to as "X" being "painted blue", but I've never seen that terminology in the C standards themselves.) But forcing extra scans is part of how we trick the preprocessor into doing "recursive" macros, and the number of scans is what sets the upper limit on how many times our "recursive" macros can expand.
Personally, I dislike forcing more scans than needed, and I don't like being capped to some number of scans. Throwing a hard-coded "large enough" quantity at a problem where the actual need is variable is pretty crude engineering. But this is the simplest technique to get started with, and it's the best we have if we want to keep C-style argument list syntax, because the only way to automatically get just the number of scans needed also forces changing calls from "MY_MACRO(foo, bar, qux)" to "MY_MACRO((foo)(bar)(qux))".
4 notes
·
View notes
Note
Trick or treat!!
Hi Julia! :) For you I have this snippet of C++ preprocessor directives I wrote sometime in 2018
42 notes
·
View notes
Text
Avisynth Basics - Resizing and Sharpening for Gifs
Prerequisites
Avisynth (Wikipedia)
How to Use Avisynth For Gif Making by MichieTuts
Installing Avisynth by brandinator
Tumblr Dashboard Image Display Sizes by Unwrapping Tumblr
This post details my process for using Avisynth to resize a video file. The video file can then be edited and converted to a gif.
I learned how to use Avisynth through the posts linked above. I highly recommend reading through them; they're very detailed and easy to follow. By comparison, this is a basic guide as it only offers one method for using Avisynth.
In this post, I cover the following:
Why use Avisynth?
Using Avisynth to resize a video clip
This post assumes that you've already installed Avisynth.
💡 Why use Avisynth?
Avisynth is a frameserver that takes a video file as input and resizes it for editing. The width of a Tumblr post is 540 pixels (px); with Avisynth, we can resize video files so that they fit that criteria. (For context, a 1080p (HD) YouTube video is 1920 x 1080 px.)
While Photoshop is able to resize images (Image > Image Size), it's not as accurate as Avisynth is.
Here are two gifs that have been resized through different software:
The difference is subtle, but the left gif (Avisynth) appears more detailed to me!
However, please note that I didn't run any Photoshop sharpening on the right gif. When learning how to resize and sharpen gifs in Photoshop, I followed rubyredwisp's Gif Sharpening Tutorial.
🎥 Using Avisynth to resize a video clip
The following steps detail how I use Avisynth to resize videos. The final product, an .avi file, can be imported into your editor (eg. Photoshop) and edited there.
① Choose a video file that you'd like to gif.
For the purpose of this tutorial, I work with a screenrecording that I took of Dragon Age 2.
② Navigate to your Avisynth folder and locate the normalwebmrange script.
This may differ depending on how you installed Avisynth, but my Avisynth folder is located at \This PC\Windows (:C)\video.
normalwebmrange is a Windows batch file (.bat). I use this particular script because it allows you to clip out a few seconds of the video by specifying the start and end timestamps. These timestamps specify the video clip that will become your gif(s).
I recommend working with video clips that are 4-8 seconds long.
ⓘ This means that you may need to load your video file back into normalwebmrange to make a gif in a new timestamp range. While inconvenient, I recommend working with smaller video clips so that you're asking Avisynth to process multiple small videos rather than one large video. A larger video is more likely to crash the software.
③ Load the video file into normalwebmrange.
To do so, select and drag your video file into normalwebmrange.
④ Enter the timestamps of the portion of the video you want to clip out.
A pop-up window will appear that asks you for the "starting time in hh:mm:ss format."
For this example, I want my gif to start at about 3 minutes and 13 seconds into my video file. My start timestamp is therefore 00:03:13.
Enter this information, then hit the Enter key.
Next, enter the "ending time in hh:mm:ss format." (For this example, my end timestamp is 00:03:21.) Hit the Enter key.
normalwebmrange will then generate a bunch of log lines. After, it will automatically open two things:
A tab in your computer's default web browser.
An Avisynth window.
⑤ Specify the resizing details for your gif.
Navigate to the browser tab that normalwebmrange opened. There are several fields for you to fill out here.
GIF Size - This is the width and height of your gif. For more details on Tumblr post sizes, see Tumblr Dashboard Image Display Sizes. After filling this out, you may have to adjust your video clip in the preview box (below the white textbox).
Opacity - Leave this value at 100.
Preprocessor - I always use qtgmc 30 slow for the framerate and debilinear sharpening. "30" refers to how many frames per second (fps) you want your gif to display; I find that the alternative, 60 fps, is overkill for Tumblr gifs. "Slow" means that Avisynth will take longer to process your video, but this results in better quality.
Extra Sharpening - I don't use this field, but feel free to experiment!
After filling out all of the fields, copy all of the text in the white textbox.
⑥ Enter the resizing information in Avisynth.
Navigate to the Avisynth window that normalwebmrange opened.
Paste the text you just copied on line 17:
Your Avisynth window should now look something like this:
Select File > Save Script.
Close the Avisynth window.
This automatically launches another Avisynth window called VirtualDub. Here, you can watch Avisynth resize and sharpen your video clip in real time!
Once the VirtualDub window automatically closes, you'll know that your video clip has been fully processed and is now ready for editing.
? Where did my video clip save to? If you go back to your Avisynth folder (\This PC\Windows (:C)\video), open the \temp folder. The .avi file named "video" is your resized and sharpened video clip!
17 notes
·
View notes
Note
How DOES the C preprocessor create two generations of completely asinine programmers??
oh man hahah oh maaan. ok, this won't be very approachable.
i don't recall what point i was trying to make with the whole "two generations" part but ill take this opportunity to justifiably hate on the preprocessor, holy fuck the amount of damage it has caused on software is immeasurable, if you ever thought computer programmers were smart people on principle...
the cpp:
there are like forty preprocessor directives, and they all inject a truly mind-boggling amount of vicious design problems and have done so for longer than ive been alive. there really only ever needed to be one: #include , if only to save you the trouble of manually having to copy header files in full & paste them at the top of your code. and christ almighty, we couldn't even get that right. C (c89) has way, waaaay fewer keywords than any other language. theres like 30, and half of those aren't ever used, have no meaning or impact in the 21st century (shit like "register" and "auto"). and C programmers still fail to understand all of them properly, specifically "static" (used in a global context) which marks some symbol as inelligible to be touched externally (e.g. you can't use "extern" to access it). the whole fucking point of static is to make #include'd headers rational, to have a clear seperation between external, intended-to-be-accessed API symbols, and internal, opaque shit. nobody bothers. it's all there, out in the open, if you #include something, you get all of it, and brother, this is only the beginning, you also get all of its preprocessor garbage.
this is where the hell begins:
#if #else
hey, do these look familiar? we already fucking have if/else. do you know what is hard to understand? perfectly minimally written if/else logic, in long functions. do you know what is nearly impossible to understand? poorly written if/else rats nests (which is what you find 99% of the time). do you know what is completely impossible to understand? that same poorly-written procedural if/else rat's nest code that itself is is subject to another higher-order if/else logic.
it's important to remember that the cpp is a glorified search/replace. in all it's terrifying glory it fucking looks to be turing complete, hell, im sure the C++ preprocessor is turing complete, the irony of this shouldn't be lost on you. if you have some long if/else logic you're trying to understand, that itself is is subject to cpp #if/#else, the logical step would be to run the cpp and get the output pure C and work from there, do you know how to do that? you open the gcc or llvm/clang man page, and your tty session's mem usage quadruples. great job idiot. trying figuring out how to do that in the following eight thousand pages. and even if you do, you're going to be running the #includes, and your output "pure C" file (bereft of cpp logic) is going to be like 40k lines. lol.
the worst is yet to come:
#define #ifdef #ifndef (<- WTF) #undef you can define shit. you can define "anything". you can pick a name, whatever, and you can "define it". full stop. "#define foo". or, you can give it a value: "#define foo 1". and of course, you can define it as a function: "#define foo(x) return x". wow. xzibit would be proud. you dog, we heard you wanted to kill yourself, so we put a programming language in your programming language.
the function-defines are pretty lol purely in concept. when you find them in the wild, they will always look something like this:
#define foo(x,y) \ (((x << y)) * (x))
i've seen up to seven parens in a row. why? because since cpp is, again, just a fucking find&replace, you never think about operator precedence and that leads to hilarious antipaterns like the classic
#define min(x,y) a < b ? a : b
which will just stick "a < b ? a: b" ternary statement wherever min(.. is used. just raw text replacement. it never works. you always get bitten by operator precedence.
the absolute worst is just the bare defines:
#define NO_ASN1 #define POSIX_SUPPORTED #define NO_POSIX
etc. etc. how could this be worse? first of all, what the fuck are any of these things. did they exist before? they do now. what are they defined as? probably just "1" internally, but that isn't the point, the philosophy here is the problem. back in reality, in C, you can't just do something like "x = 0;" out of nowhere, because you've never declared x. you've never given it a type. similar, you can't read its value, you'll get a similar compiler error. but cpp macros just suddenly exist, until they suddenly don't. ifdef? ifndef? (if not defined). no matter what, every permutation of these will have a "valid answer" and will run without problem. let me demonstrate how this fucks things up.
do you remember "heartbleed" ? the "big" openssl vulnerability ? probably about a decade ago now. i'm choosing this one specifically, since, for some reason, it was the first in an annoying trend for vulns to be given catchy nicknames, slick websites, logos, cable news coverage, etc. even though it was only a moderate vulnerability in the grand scheme of things...
(holy shit, libssl has had huge numbers of remote root vulns in the past, which is way fucking worse, heartbleed only gave you a random sampling of a tiny bit of internal memory, only after heavy ticking -- and nowadays, god, some of the chinese bluetooth shit would make your eyeballs explode if you saw it; a popular bt RF PHY chip can be hijacked and somehow made to rewrite some uefi ROMs and even, i think, the microcode on some intel chips)
anyways, heartbleed, yeah, so it's a great example since you could blame it two-fold on the cpp. it involved a generic bounds-checking failure, buf underflow, standard shit, but that wasn't due to carelessness (don't get me wrong, libssl is some of the worst code in existence) but because the flawed cpp logic resulted in code that:
A.) was de-facto worthless in definition B.) a combination of code supporting ancient crap. i'm older than most of you, and heartbleed happened early in my undergrad. the related legacy support code in question hadn't been relevant since clinton was in office.
to summarize, it had to do with DTLS heartbeats. DTLS involves handling TLS (or SSLv3, as it was then, in the 90s) only over UDP. that is how old we're talking. and this code was compiled into libssl in the early 2010s -- when TLS had been the standard for a while. TLS (unlike SSLv3 & predecessors) runs over TCP only. having "DTLS heartbeat support in TLS does not make sense by definition. it is like drawing a triangle on a piece of paper whose angles don't add up to 180.
how the fuck did that happen? the preprocessor.
why the fuck was code from last century ending up compiled in? who else but!! the fucking preprocessor. some shit like:
#ifndef TCP_SUPPORT <some crap related to UDP heartbeats> #endif ... #ifndef NO_UDP_ONLY <some TCP specific crap> #endif
the header responsible for defining these macros wasn't included, so the answer to BOTH of these "if not defined" blocks is true! because they were never defined!! do you see?
you don't have to trust my worldview on this. have you ever tried to compile some code that uses autoconf/automake as a build system? do you know what every single person i've spoken to refers to these as? autohell, for automatic hell. autohell lives and dies on cpp macros, and you can see firsthand how well that works. almost all my C code has the following compile process:
"$ make". done. Makefile length: 20 lines.
the worst i've ever deviated was having a configure script (probably 40 lines) that had to be rune before make. what about autohell? jesus, these days most autohell-cursed code does all their shit in a huge meta-wrapper bash script (autogen.sh), but short of that, if you decode the forty fucking page INSTALL doc, you end up with:
$ automake (fails, some shit like "AUTOMAKE_1.13 or higher is required) $ autoconf (fails, some shit like "AUTOMCONF_1.12 or lower is required) $ aclocal (fails, ???) $ libtoolize (doesn't fail, but screws up the tree in a way that not even a `make clean` fixes $ ???????? (pull hair out, google) $ autoreconf -i (the magic word) $ ./configure (takes eighty minutes and generates GBs of intermediaries) $ make (runs in 2 seconds)
in conclusion: roflcopter
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ disclaimer | private policy | unsubscribe
159 notes
·
View notes
Text
Barry Vercoe (24 July 1937 – 16 June 2025)
I will not recapitulate what others have said in tribute to Barry Vercoe. You can read the Wikipedia article, or Richard Boulanger’s tribute (which is quoted in full here), or look at Barry’s old home page at the Massachusetts Institute of Technology, or read his New Zealand obituary.
Here I will offer my personal thanks to Barry for creating what, in my considered opinion, is one of the best musical instruments in history — Csound. I use it for almost all of my musical compositions.
There are now other systems, such as Max or Supercollider, that can do all, or almost all, of what Csound does. However, Csound came first, and is an ancestor of these systems. For at least some composers, such as myself, Csound is still easier to use, and perhaps more powerful. And just because it is older, Csound has the huge advantage of a very large base of running musical examples and pieces.
Here I will also offer my appreciation of Barry’s design choices and his implementation of Csound. My appreciation is based on my own experience, not only as an intensive user, but also as a sometime member of the Csound development team, when I contributed a number of features to Csound and came to understand Barry’s outstanding ability as a computer programmer.
There are some things I definitely do not like about the Csound code, mainly the cryptic names, and the use of preprocessor macros. Aside from that, here are a few of the good things in Barry’s code:
Of course the big home run was writing Csound in platform-neutral C, still the most performant programming language, and still available on more platforms than any other.
The extreme simplicity and efficiency of the inner loop for running Csound performances.
Invisible, automatic handling of multiple notes playing at the same time, for the same instrument.
The extremely flexible design for unit generators (opcodes), the building blocks of sound synthesis. Essentially, although written in C, Barry’s unit generators are classes -- data structures that derive from a virtual base class, and include methods for operating on their own data. The virtual base class idea makes it quite easy to extend Csound with new unit generators, and now even plugin unit generators.
The musical power and flexibility of Csound’s score language, which permits the user to define any set of fields for an event; and these fields are not limited to integer values, but are real numbers. Furthermore, based on his experience as a composer, Barry made sure his score language could handle tied notes, polyphony, changes of tempo, and so on. This is far more powerful than MIDI.
The policy of complete backwards compatibility. The very first examples and compositions still run on today's Csound!
Based on Barry's foundation, the current implementation of Csound (far more capable than the original) remains highly efficient, flexible, and easy to extend.
3 notes
·
View notes
Text
What Is The Difference Between Web Development & Web Design?
In today’s world, we experience the growing popularity of eCommerce businesses. Web designing and web development are two major sectors for making a difference in eCommerce businesses. But they work together for publishing a website successfully. But what’s the difference between a web designers in Dubai and a web developer?
Directly speaking, web designers design and developers code. But this is a simplified answer. Knowing these two things superficially will not clear your doubt but increase them. Let us delve deep into the concepts, roles and differentiation between web development and website design Abu Dhabi.

What Is Meant By Web Design?
A web design encompasses everything within the oeuvre of a website’s visual aesthetics and utility. This might include colour, theme, layout, scheme, the flow of information and anything related to the visual features that can impact the website user experience.
With the word web design, you can expect all the exterior decorations, including images and layout that one can view on their mobile or laptop screen. This doesn’t concern anything with the hidden mechanism beneath the attractive surface of a website. Some web design tools used by web designers in Dubai which differentiate themselves from web development are as follows:
● Graphic design
● UI designs
● Logo design
● Layout
● Topography
● UX design
● Wireframes and storyboards
● Colour palettes
And anything that can potentially escalate the website’s visual aesthetics. Creating an unparalleled yet straightforward website design Abu Dhabi can fetch you more conversion rates. It can also gift you brand loyalty which is the key to a successful eCommerce business.
What Is Meant By Web Development?
While web design concerns itself with all a website’s visual and exterior factors, web development focuses on the interior and the code. Web developers’ task is to govern all the codes that make a website work. The entire web development programme can be divided into two categories: front and back.
The front end deals with the code determining how the website will show the designs mocked by a designer. While the back end deals entirely with managing the data within the database. Along with it forwarding the data to the front end for display. Some web development tools used by a website design company in Dubai are:
● Javascript/HTML/CSS Preprocessors
● Template design for web
● GitHub and Git
● On-site search engine optimisation
● Frameworks as in Ember, ReactJS or Angular JS
● Programming languages on the server side, including PHP, Python, Java, C#
● Web development frameworks on the server side, including Ruby on Rails, Symfony, .NET
● Database management systems including MySQL, MongoDB, PostgreSQL
Web Designers vs. Web Developers- Differences
You must have become acquainted with the idea of how id web design is different from web development. Some significant points will highlight the job differentiation between web developers and designers.
Generally, Coding Is Not A Cup Of Tea For Web Designers:
Don’t ever ask any web designers in Dubai about their coding knowledge. They merely know anything about coding. All they are concerned about is escalating a website’s visual aspects, making them more eyes catchy.
For this, they might use a visual editor like photoshop to develop images or animation tools and an app prototyping tool such as InVision Studio for designing layouts for the website. And all of these don’t require any coding knowledge.
Web Developers Do Not Work On Visual Assets:
Web developers add functionality to a website with their coding skills. This includes the translation of the designer’s mockups and wireframes into code using Javascript, HTML or CSS. While visual assets are entirely created by designers, developer use codes to implement those colour schemes, fonts and layouts into the web page.
Hiring A Web Developer Is Expensive:
Web developers are more expensive to hire simply because of the demand and supply ratio. Web designers are readily available as their job is much simpler. Their job doesn’t require the learning of coding. Coding is undoubtedly a highly sought-after skill that everyone can’t entertain.
Final Thoughts:
So if you look forward to creating a website, you might become confused. This is because you don’t know whether to opt for a web designer or a developer. Well, to create a website, technically, both are required. So you need to search for a website design company that will offer both services and ensure healthy growth for your business.
2 notes
·
View notes
Text
I work in formal methods and computational mathematics. I spend a lot of time working on SAT solvers and CAS engines and the like.
Today, I happened to be working on a SAT solver. And noticed the sat solver had another sat solver inside of it. In retrospect, that should have been obvious.
Now, for those who don't know, here is what a SAT solver does, and what its applications are:
A SAT solver takes a statement made of negations, conjunctions, disjunctions, and atomic statements and then returns an assignment of the atomic statements that makes the statement true.
For example: A or B, this can be satisfied as A = True and B = False.
This is the quintessential NP-complete problem. All the others can actually be reduced to it. So for the list of problems that a SAT solver can solve, see link below.
Modern methods have been trying to make it really really fast. Unfortunately, we haven't been able to beat the polynomial time barrier. Most people think it's impossible, but no one has actually shown that it is impossible.
I'm really naive, perhaps, in that I think P=NP. I may just believe that because it'd be so cool if it were true. So far no one has proved me wrong.
Now, whilst working on one of these SAT solvers, I realised something: the input for the solver has to be in conjunctive normal form, and there's a preprocessor that converts the statement into conjunctive normal form, that is
Anding a bunch of ors of atomic statements and their negations.
(a or b) and (c or (not a)) and (a or c) and ((not a) or c or f)
To get them there, the preprocessor system that converts things into conjunctive normal form has several rules about manipulation of these statements. As it happens, it is robust enough to do the same, but into disjunctive normal form, which in this case happens to be:
(b and c) or (a and c)
Which does actually accomplish what the SAT solver set out to do.
Now, does this system run slower and less effectively than the actual system? Yes. But I find it funny that there's a SAT solver in my SAT solver.
4 notes
·
View notes
Text
The C Programming Language Compliers – A Comprehensive Overview
C is a widespread-purpose, procedural programming language that has had a profound have an impact on on many different contemporary programming languages. Known for its efficiency and energy, C is frequently known as the "mother of all languages" because many languages (like C++, Java, and even Python) have drawn inspiration from it.
C Lanugage Compliers
Developed within the early Seventies via Dennis Ritchie at Bell Labs, C changed into firstly designed to develop the Unix operating gadget. Since then, it has emerge as a foundational language in pc science and is still widely utilized in systems programming, embedded systems, operating systems, and greater.
2. Key Features of C
C is famous due to its simplicity, performance, and portability. Some of its key functions encompass:
Simple and Efficient: The syntax is minimalistic, taking into consideration near-to-hardware manipulation.
Fast Execution: C affords low-degree get admission to to memory, making it perfect for performance-critical programs.
Portable Code: C programs may be compiled and run on diverse hardware structures with minimal adjustments.
Rich Library Support: Although simple, C presents a preferred library for input/output, memory control, and string operations.
Modularity: Code can be written in features, improving readability and reusability.
Extensibility: Developers can without difficulty upload features or features as wanted.
Three. Structure of a C Program
A primary C application commonly consists of the subsequent elements:
Preprocessor directives
Main function (main())
Variable declarations
Statements and expressions
Functions
Here’s an example of a easy C program:
c
Copy
Edit
#include <stdio.H>
int important()
printf("Hello, World!N");
go back zero;
Let’s damage this down:
#include <stdio.H> is a preprocessor directive that tells the compiler to include the Standard Input Output header file.
Go back zero; ends this system, returning a status code.
4. Data Types in C
C helps numerous facts sorts, categorised particularly as:
Basic kinds: int, char, glide, double
Derived sorts: Arrays, Pointers, Structures
Enumeration types: enum
Void kind: Represents no fee (e.G., for functions that don't go back whatever)
Example:
c
Copy
Edit
int a = 10;
waft b = three.14;
char c = 'A';
five. Control Structures
C supports diverse manipulate structures to permit choice-making and loops:
If-Else:
c
Copy
Edit
if (a > b)
printf("a is more than b");
else
Switch:
c
Copy
Edit
switch (option)
case 1:
printf("Option 1");
smash;
case 2:
printf("Option 2");
break;
default:
printf("Invalid option");
Loops:
For loop:
c
Copy
Edit
printf("%d ", i);
While loop:
c
Copy
Edit
int i = 0;
while (i < five)
printf("%d ", i);
i++;
Do-even as loop:
c
Copy
Edit
int i = zero;
do
printf("%d ", i);
i++;
while (i < 5);
6. Functions
Functions in C permit code reusability and modularity. A function has a return kind, a call, and optionally available parameters.
Example:
c
Copy
Edit
int upload(int x, int y)
go back x + y;
int important()
int end result = upload(3, 4);
printf("Sum = %d", result);
go back zero;
7. Arrays and Strings
Arrays are collections of comparable facts types saved in contiguous memory places.
C
Copy
Edit
int numbers[5] = 1, 2, three, 4, five;
printf("%d", numbers[2]);�� // prints three
Strings in C are arrays of characters terminated via a null character ('').
C
Copy
Edit
char name[] = "Alice";
printf("Name: %s", name);
8. Pointers
Pointers are variables that save reminiscence addresses. They are powerful but ought to be used with care.
C
Copy
Edit
int a = 10;
int *p = &a; // p factors to the address of a
Pointers are essential for:
Dynamic reminiscence allocation
Function arguments by means of reference
Efficient array and string dealing with
9. Structures
C
Copy
Edit
struct Person
char call[50];
int age;
;
int fundamental()
struct Person p1 = "John", 30;
printf("Name: %s, Age: %d", p1.Call, p1.Age);
go back 0;
10. File Handling
C offers functions to study/write documents using FILE pointers.
C
Copy
Edit
FILE *fp = fopen("information.Txt", "w");
if (fp != NULL)
fprintf(fp, "Hello, File!");
fclose(fp);
11. Memory Management
C permits manual reminiscence allocation the usage of the subsequent functions from stdlib.H:
malloc() – allocate reminiscence
calloc() – allocate and initialize memory
realloc() – resize allotted reminiscence
free() – launch allotted reminiscence
Example:
c
Copy
Edit
int *ptr = (int *)malloc(five * sizeof(int));
if (ptr != NULL)
ptr[0] = 10;
unfastened(ptr);
12. Advantages of C
Control over hardware
Widely used and supported
Foundation for plenty cutting-edge languages
thirteen. Limitations of C
No integrated help for item-oriented programming
No rubbish collection (manual memory control)
No integrated exception managing
Limited fashionable library compared to higher-degree languages
14. Applications of C
Operating Systems: Unix, Linux, Windows kernel components
Embedded Systems: Microcontroller programming
Databases: MySQL is partly written in C
Gaming and Graphics: Due to performance advantages
2 notes
·
View notes
Text
The more I use C and C++ the less I hate certain aspects of them. Not because I no longer see them as bad, but because they're now a bad I know.
That said I will never get over the decision to separate definition and implementation between two files. It incentivizes me to just shove all my code in the main file because then I don't need to write any headers. If there was a way to just include .c or .cpp files directly I might actually use these languages for personal projects ever. Like yeah I know why things are the way they are but jesus christ it makes me never want to use this language because tbh I'm never writing code in a context where the distinction between interface and implementation matter. Every other language I use has proper import statements and let you just include shit and not have to fuss with preprocessor macros to ensure you don't accidentally define the same struct 20 times.
2 notes
·
View notes
Text
An interesting thing about C is that like 90% of the special character-lookalikes are valid for identifiers.
This means you can write nonsense like this:
Now, if you had poor a) eyesight and b) understanding of the C preprocessor, you might think that this program would print 5. That is not the case.
No, instead #undef t does nothing, and we've defined a second variable named tᅠ=ᅠ5;ᅠcharᅠg (web browsers seem to render HALFWIDTH HANGUL FILLER differently) and initialized it to 4. t is unaffected.
Now is this specific example very convincing? Not really. But I bet you could do some interesting things in an underhanded or obfuscated C challenger with a properly placed FULLWIDTH SEMICOLON or MODIFIER LETTER COLON. (Greek question mark looks better but throws up normalization errors with gcc's default settings. These don't.)
2 notes
·
View notes
Text
sometimes I really wish C# had C/C++ style preprocessor macros. I know they have their issues, especially when it comes to accidental code obfuscation, but sometimes sometimes being able to use semantic similarities between two otherwise entirely different objects can be really handy.
like the API I'm working with has a bunch of various event classes that all use paired Subscribe and Unsubscribe methods, and I'd like to have it so every time I Subscribe to an event, that same event also gets added to a list to make sure it gets Unsubscribed later, but since most events calls use different types of arguments, the method calls are functionally too different for a simple generic solution.
If it were C/C++, I'd just be able to do #define SUBEVENT(ev, fun) ev.Subscribe(fun); unsubscribe.Add(() => { ev.Unsubscribe(fun); }); and call it a day, but since C# doesn't have the C preprocessor, it depends on me remembering to manually add each subscribed event to the unsubscribe list.
Feels like there's got to be a better way, but hells if I know what it'd be.
6 notes
·
View notes
Text
When you think about it, the C preprocessor isn't really a C preprocessor, is it?
:3
7 notes
·
View notes
Text
Ok. I need a consensus. C/C++ programmers.

13 notes
·
View notes
Text
having flashbacks of looking at another bsd devs screen years ago at a hackathon during our libssl rewrite after…whatever that horrible libssl vuln was..
literally not even recognizable as C at first. they created their own weird byzantine convoluted sludge language with preprocessor macros and, my god, after closer inspection the sins they committed were unspeakable. we aren’t talking like #IFNDEF level shenanigans. every preprocessor sin committed at every level severity and in every combination possible. a permutation-complete reference work on how to go to hell.
it would be like building the wallet and grommace bed/breakfast contraption in real life, and then trying it for the first time, dislocating several vertebrae from the bed spring, breaking both legs falling through the floor, hitting your forehead on the table & concussing you, and then getting blasted with superheated porridge that has also started a fire. you yell “help me grommit!!” but it is a normal real life dog.
103 notes
·
View notes
Text
Last Monday of the Week 2023-08-07
Rainy season has come
Listening: Acid Magus' new album Hope Is Heavy is out, here's Progeneration.
Love Acid Magus. If you buy this album you also get a 15 minute long rearrangement of the three core songs from their first album which is absolutely killer.
Reading: Halfway through The Will to Battle. Notes to follow elsewhere as I make more progress.
Watching: Mermaid: The Body Found, at movie night. A mockumentary about mermaids being real shown on Animal Planet that was taken seriously by some people. Extremely stupid, great for heckling.
Making: Cinnabar is fully assembled, following a minor adventure with the power supply and finally fully stocking up on SATA cables. I'll put together a final parts list now that she's settled and I can actually use her in my day-to-day.
Playing: Mostly just kicking the tyres on Cinnabar with a few small runs in high end games, but I started Control and got to the first control point. I like the atmosphere but I can tell it's going to take me forever to get through this game with the amount of lore scattered around these cavernous halls.
Tools and Equipment: C/++ has a vars array of macros to print metadata about your code including the filename, line and function that a macro falls inside of. This is extremely handy for writing easy to use printf debugging code. GCC adds some extensions on top of even these.
8 notes
·
View notes
Text
Price: [price_with_discount] (as of [price_update_date] - Details) [ad_1] C is a popular programming language which is commonly used by scientists and engineers to write programs for any specific application. C is also a widely accepted programming language in the software industries. This beginner's guide to computer programming is for student programmers to effectively write programs for solving numerical problems. All that is required of a beginner programmer is not experience in computing but interest in computing. The programs illustrated in the book have been accumulated, experimented and tested by the author during his teaching of the subject to a few thousand students in over a decade. In addition, numerous problems are adapted form university question papers. Short questions and answers and objective questions are an added feature. All these would build confidence of the students and those appearing for interview/viva voce in a practical lab. The special topic of the book is c graphics and animation which helps students develop simple programs to generate geometrical and graphical objects.About the authort jeyapoovan specializes in programming languages, computer graphics, autocad and related software packages. He has an ms in software systems form birla institute of technology and science (bits), pilani and a b.Tech. From college of engineering, trivandrum. He has a rich experience of 14 years and is currently senior faculty, hindustan college of engineering, chennai.Table of contents introduction to computers, introduction to programming, fundamentals of c language, input/output functions and statements, control statements in c, loop control structures in c, arrays and subscripted variables, string manipulations in c, functions in c, structures and unions, pointers, files, c preprocessor and command line arguments, graphics using c Publisher : Vikas Publishing House Pvt Ltd; First Edition (7 July 2004) Language : English Paperback : 412 pages ISBN-10 : 8125912118 ISBN-13 : 978-8125912118 Item Weight : 500 g Dimensions : 19.8 x 13 x 1.5 cm Country of Origin : India [ad_2]
0 notes